package pro.softzhang.algo.lc300;

import pro.softzhang.algo.flag.knowledge.KGreedy;
import pro.softzhang.algo.flag.x.XOptimal;

/**
 *
 */
public class LC334_IncreasingTripletSubsequence {
    public static void main(String[] args) {

    }

    /**
     * 贪心思想
     */
    @KGreedy
    @XOptimal
    static class Solution {
        public boolean increasingTriplet(int[] nums) {
            // 不足长度3
            if(nums.length < 3) {
                return false;
            }

            int first = nums[0], second = Integer.MAX_VALUE;
            for (int i = 1; i < nums.length; i++) {
                int num = nums[i];
                if(num > second) {
                    return true;
                } else if (num > first) {
                    second = num;
                } else {
                    first = num;
                }
            }
            return false;
        }
    }
}
